package net.suntec.mrs.message;

import java.nio.ByteBuffer;

public class MessageBuffer {

	/** 消息类型(1:消息取入,2:消息取出) */
	private ByteBuffer type;

	/** 消息内容的字节数 */
	private ByteBuffer contentLength;

	/** 用户令牌 */
	private ByteBuffer token;

	/** 消息内容 */
	private ByteBuffer content;

	/** 已经读取到消息内容的合计长度 */
	private int hasReadContentSize = 0;

	private MessageContentHandler msgHandler;

	public MessageBuffer( int content_size, MessageContentHandler msgHandler ) {

		// 消息类型(1字节)
		this.type = ByteBuffer.allocate( 1 );
		// 消息长度(3字节)
		this.contentLength = ByteBuffer.allocate( 3 );
		// 用户令牌(32字节)
		this.token = ByteBuffer.allocate( 32 );
		// 消息内容(字节数灵活指定)
		this.content = ByteBuffer.allocate( content_size );

		this.msgHandler = msgHandler;
	}

	public ByteBuffer getType() {
		return type;
	}

	public ByteBuffer getContentSize() {
		return contentLength;
	}

	public ByteBuffer getToken() {
		return token;
	}

	public ByteBuffer getContent() {
		return content;
	}

	public ByteBuffer[] getAllBuffer() {
		ByteBuffer[] buffers = new ByteBuffer[] { this.type, this.contentLength, this.token,
				this.content };
		return buffers;
	}

	public int getHasReadContentSize() {
		return hasReadContentSize;
	}

	public void setHasReadContentSize( int hasReadContentSize ) {
		this.hasReadContentSize = hasReadContentSize;
	}

	public MessageContentHandler getMsgHandler() {
		return msgHandler;
	}
}
